#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> intersect(vector<int>& nums1, vector<int>& nums2) {
        unordered_map<int, int> hash;
        for (auto& e : nums1)
        {
            hash[e]++;
        }
        vector<int> res;
        for (auto& e : nums2)
        {
            if (--hash[e] >= 0) res.push_back(e);
        }
        return res;
    }
};